/**  拖拽存放类
 *
 *功能:可做排班,货物配送,人员调配等系统
 *
 *作者:Monkey Lee
 *
 *时间:2010-11-02
 *
 *版本:1.0
 *
**/
function objTFinit(objtype){

 var objTF = new Object;

 objTF.shuliangtiaot;                           //仓库数量显示条
 objTF.shuliangtiaof;                           //放置表格数量显示条

 objTF.type = objtype?objtype:null              //仓库数据控制类型

 objTF.clone;                                   //仓库表格克隆对象
 objTF.clonei = 0                               //克隆对象索引,累加值

 objTF.t;                                        //仓库表格对象集合
 objTF.tcolor;                                   //仓库表格背景色
 objTF.tnum;                                     //仓库表格货物数量
 objTF.ttiji;                                    //货物所占放置表格的空间

 objTF.f;                                        //放置表格对象集合
 objTF.fcolor;                                   //放置表格背景色
 objTF.fnum;                                     //放置表格的空间大小
 objTF.ffn;                                      //放置表格的预处理函数


 objTF.data = new Array();                       //仓库表格数据对象集合
 objTF.dataf = new Array();                      //放置表格数据对象集合
 objTF.index;                                    //仓库数据对象索引
 objTF.indexf;                                   //放置表格数据对象索引

 objTF.empty = false;                            //总事件控制器 布尔类型


 objTF.client_X;                                  //拖拽初始定位X轴
 objTF.client_Y;                                  //拖拽初始定位Y轴



/** 拖动作
 *
 *@param object  objT         仓库单元格对象
 *
 *@param array   objTnum      给每个单元格添加货物数量,可选
 *
 *@param string  objTcolor    单元格背景色
 *
 *@param int     objTtiji     货物体积
 *
 **/
 objTF.T = function(objT,objTnum,objTslt,objTcolor,objTtiji){
    this.t = objT;
    this.tnum = objTnum?objTnum:[999999999999];
    this.shuliangtiaot = objTslt?objTslt:null
    this.tcolor = objTcolor?objTcolor:'---';
    this.ttiji = objTtiji?objTtiji:[1];

    this.init('t');
    this.t.mousedown(function(event){
        //if(objTF.empty == true){ return false; }
        var Event =  event || window.event;

      if(Event.button == 0 || Event.button == 1){

        var thisObj = $(this);
        var offset = thisObj.offset();

        if(thisObj.attr('num') == '0'){ alert('空了');return false;}
        objTF.index = thisObj.attr('index');

        objTF.data[objTF.index] = thisObj;

        var clone = thisObj.clone().attr('type','xin').attr('id','clone'+objTF.clonei).css('display','block').css('position','absolute').css('left',offset.left+20+'px').css('top',offset.top).css('cursor','default').html(thisObj.get(0).innerHTML.replace(/<div.*>/ig,''));

        $('body').append(clone);

        clone.mousedown(objTF.CloneDown)
        clone.get(0).oncontextmenu=(objTF.CloneDown2);

        var tnum =  objTF.data[objTF.index].attr('num');
        objTF.data[objTF.index].attr('num',tnum-1);
        if(objTF.tcolor != '---' && objTF.data[objTF.index].attr('num')=='0') objTF.data[objTF.index].css('background',objTF.tcolor);


        if(objTF.shuliangtiaot){

         var tsobj = $('#t'+objTF.index);
         tsobj.html(tnum-1);
         var tsobjp = tsobj.parent();

         var tsobjp_ywidth = tsobjp.attr('ywidth');


         var tcadd =  Math.ceil(Number(tsobjp_ywidth)/Number(objTF.data[objTF.index].attr('maxnum')));

         var tsobjp_width = tsobjp.width();
         if(tsobjp_width < tcadd) tcadd = tsobjp_width;
         tsobjp.css('background',objTF.shuliangtiaot).css('width',tsobjp_width-tcadd+'px');

        }

        objTF.clonei++;
        objTF.empty = true;

     }


   });


 }


/** 放动作
 *
 * 配置放动作的属性
 *
 *@param object objF      放置表格单元格对象
 *
 *@param array  objFnum   给每个单元格添加货物数量,可选
 *
 *@param string objFcolor 单元格背景色
 *
 *@param string addorupd  是追加还是覆盖
 **/
 objTF.F = function(objF,objFnum,objFslt,objFcolor,objFfn){

   this.f = objF;
   this.fnum = objFnum?objFnum:[999999999999];
   this.shuliangtiaof = objFslt?objFslt:null
   this.fcolor = objFcolor?objFcolor:'---';
   this.ffn = objFfn;
   this.init('f');
   this.f.mouseup(objTF.FUp);

 }


/** 获取数据
 *
 *@param string type 选择哪个表格的数据
 *
 *@param array arr   需要添加的信息
 *
 *@return array data 返回数据数组
 *
 **/
  /* objTF.getData = function(type,arr){

       var data = new Array();

       if(type == 't'){

         var num = objTF.t.length;

         for(var i=0; i<num; i++){

           if(arr){
              data[arr[i]] = objTF.t.eq(i).html();
           }else{
              data[i] = objTF.t.eq(i).html();
           }

         }

       }else if(type == 'f'){

         var num = objTF.f.length;

         for(var i=0; i<num; i++){

           if(arr){
              data[arr[i]] = objTF.f.eq(i).html();
           }else{
              data[i] = objTF.f.eq(i).html();
           }

         }

       }

      return data;

   }



  objTF.jsonData = function(data){

      var data = data;
      var json = '{';

      for(var i in data){
          json += '"'+i+'":{';
          for(var j in data[i]){
              json += '"'+j+'":"'+data[i][j]+'",'
          }
          json = json.replace(/,$/,'')+'},';
      }

      json = json.replace(/,$/,'')+'}';

      return json;

  }*/




/*************************************************以下为私有方法*************************************************************************/

/** 放动作
 *
 * 执行放动作
 *
 **/
  objTF.FUp = function(event){


    var Event = event || window.event;
    if(Event.button == 0 || Event.button == 1){

      if(objTF.empty == false){return false};

      var thisObj = $(this);

      if(thisObj.attr('num') == '0'){ alert('满了'); return false;}

      var ttiji = Number(objTF.data[objTF.index].attr('tiji'));
      if(Number(thisObj.attr('num')) < ttiji){ alert('装不下了'); return false;}

      objTF.indexf = thisObj.attr('index');
      objTF.dataf[objTF.indexf] = thisObj;



         var text = thisObj.get(0).innerHTML;

         var preg = /<div.*clear.*\n*.*\/div>.*\n*.*<div.*\n*.*\/div>/ig;
         var retext1 = preg.exec(text);

         if(!retext1){
            retext1 = '';
         }

         var retext2 = text.replace(preg,'');

         thisObj.html(objTF.clone.css('position','static').attr('type','jiu'));

         //判断仓库数据控制类型
         if(!objTF.type){

           var addtext = thisObj.html();

         }else{

           var jia     = $('<span>').attr('type','jia').html('+ ');
           var thisShu = $('<span>').attr('type','math').css('font-size','12px').html('1');
           var jian    = $('<span>').attr('type','jian').html(' -');

           objTF.clone.append($('<span>').css('display','block').append(jia).append(thisShu).append(jian));
           var addtext = thisObj.html();

         }


         //判断是否有注册函数用来处理数据
         if(objTF.ffn){

           addtext =  objTF.ffn(addtext,thisObj);
         }



         thisObj.html(retext2+addtext[0]+retext1);


       var jiantiObj =  thisObj.find('div[class=jiantou]');




        jiantiObj.mousedown(function(event){

           var Event = event || window.event;

           var offset = $(this).offset();

           if(!addtext[1].clientX_kg){
              addtext[1].clientX = offset.left;
              addtext[1].clientX_kg = true;
           }

           addtext[1].huadong($(this));
           //返回false关闭禁用拖动,针对火狐
           return false;

        }).mouseover(function(){
            $(this).css('cursor','default');
        });





      //   var clones = thisObj.children('td');




         var clones = thisObj.get(0).getElementsByTagName('div');

         for(var i=0; i<clones.length-1; i++){
               //clones.eq(i).mousedown(objTF.CloneDown).get(0).oncontextmenu=objTF.CloneDown2;
              if(!objTF.type){

               clones[i].onmousedown = objTF.CloneDown;
               clones[i].oncontextmenu=objTF.CloneDown2;


              }else{

                 clones[i].oncontextmenu=objTF.CloneDown2;

                 objTF.Ttype(clones[i],ttiji);

              }

          }


      objTF.fshuliang(thisObj,ttiji,'+');



      objTF.empty = false;
    }

  }




/** 放置表格数量控制
 *
 *@param object thisObj 该放置单元格
 *
 *@param int ttiji 物品的体积
 *
 *@param string type 加or减
 *
 **/
  objTF.fshuliang = function(thisObj,ttiji,type){

      var fnum = Number(thisObj.attr('num'));

      if(type=="+"){

         thisObj.attr('num',fnum-1*ttiji);

      }else if(type=="-"){

        thisObj.attr('num',fnum+1*ttiji);

      }

      if(objTF.fcolor != '---' && objTF.tcolor && thisObj.attr('num') == '0') thisObj.css('background',objTF.fcolor);


      if(objTF.shuliangtiaof){

        var fsobj = $('#d'+thisObj.attr('index'));


        var repreg = /\/.*/ig;
        var ptext = repreg.exec(fsobj.text());
        var retext = fsobj.text().replace(repreg,'');


        if(type=="+"){

           fsobj.html(Number(retext)+1*ttiji+ptext);

        }else if(type=="-"){

           fsobj.html(Number(retext)-1*ttiji+ptext);

        }

        var fsobjp = fsobj.parent();

        var fsobjp_ywidth = fsobjp.attr('ywidth');

        var fcadd =  Math.ceil(Number(fsobjp_ywidth)/Number(thisObj.attr('maxnum')));

        var fsobjp_width = fsobjp.width();

        if(type=="+"){

            if(fsobjp_width+fcadd*ttiji > fsobjp_ywidth){
                 var gwidth = fsobjp_ywidth;
            }else{
                 var gwidth = fsobjp_width+fcadd*ttiji;
            }

         }else if(type=="-"){

             if(fsobjp_width-fcadd*ttiji < 0){
                 var gwidth = 0;
             }else{
                 var gwidth = fsobjp_width-fcadd*ttiji;
             }

          }

          fsobjp.css('background',objTF.shuliangtiaof).css('width',gwidth+'px');

       }

  }




/** 仓库数据控制(注册事件)
 *
 * 控制物品数量的加减方式
 *
 *@param object obj 克隆元素
 *
 *@param int ttiji 物品的体积
 *
 **/
   objTF.Ttype = function(obj,ttiji){

                var spanJia =  obj.getElementsByTagName('span')[1];
                    spanJia.ttiji = ttiji;

                spanJia.onmouseover = function(){

                       var thisObj = $(this);
                       thisObj.css('color','#f00');

                }

                spanJia.onmouseout = function(){

                       var thisObj = $(this);
                       thisObj.css('color','');

                }

                spanJia.onclick = function(){

                       var thisObj = $(this);
                       var ttiji = thisObj.attr('ttiji');

                       objTF.Ttype_(thisObj,'+',ttiji);

                }



                var spanJian =  obj.getElementsByTagName('span')[3];
                    spanJian.ttiji = ttiji;

                spanJian.onmouseover = function(){

                        var thisObj = $(this);
                       thisObj.css('color','#f00');

                }

                spanJian.onmouseout = function(){

                        var thisObj = $(this);
                       thisObj.css('color','');

                }

                spanJian.onclick = function(){

                     var thisObj = $(this);
                     var ttiji = thisObj.attr('ttiji');

                     objTF.Ttype_(thisObj,'-',ttiji);

                }


   }




/** 仓库数据控制(执行事件1)
 *
 * 控制物品数量的加减方式
 *
 *@param object obj 加减符号对象
 *
 *@param string type 加or减
 *
 *@param int ttiji  仓库物品体积
 *
 **/
   objTF.Ttype_ = function(obj,type,ttiji){

                var thisObj = obj;
                var thisObjppp = thisObj.parent().parent().parent();

                switch(type){

                  case '+':   var nextObj = thisObj.next('span[type=math]');

                              var nextObjVal = Number(nextObj.html());

                              //执行仓库数据控制2 返货物品数量
                              var tnum = objTF.Ttype__(thisObj,'+');

                              if(!tnum){
                                 alert('空了');
                                 return false;
                              }

                              if(nextObjVal == thisObjppp.attr('maxnum')){
                                 alert('满了');
                                 return false;
                               }

                              nextObj.html(nextObjVal+1);

                              if(nextObjVal+1 == thisObjppp.attr('maxnum')){
                                  thisObjppp.css('background',objTF.fcolor);
                              }

                              //执行放置表格数量条和max数量控制
                              objTF.fshuliang(thisObjppp,ttiji,'+');
                              break;


                   case '-':   var nextObj = thisObj.prev('span[type=math]');

                               var nextObjVal = Number(nextObj.html());

                               if(nextObjVal == 1){ return false;}

                               var tnum = objTF.Ttype__(thisObj,'-');

                               nextObj.html(nextObjVal-1);
                               thisObjppp.css('background','');

                               objTF.fshuliang(thisObjppp,ttiji,'-');
                               break;


                   default : break;

               }

   }




/** 仓库数据控制(执行事件2)
 *
 * 控制物品数量的加减方式
 *
 *@param object obj 克隆元素
 *
 *@param string type 加or减
 *
 **/
   objTF.Ttype__ = function(obj,type){

         //找到该克隆元素
          var cloneObj = obj.parent().parent();
          var cloneIndex = cloneObj.attr('index');

          //用循环找到该克隆元素对应的物品并控制数量显示条和剩余数量
          for(var i=0; i<objTF.t.length; i++){

               var tobj = objTF.t.eq(i);

               var tobjIndex = tobj.attr('index');

               if(tobjIndex == cloneIndex){

                   if(tobj.attr('num') == 0 && type=='+'){

                        return false;
                   }

                    if(objTF.shuliangtiaot){

                          var fsobj = $('#t'+tobj.attr('index'));

                          if(type=='+'){
                             fsobj.html(Number(fsobj.text())-1);
                          }else if(type=='-'){
                             fsobj.html(Number(fsobj.text())+1);
                          }


                          var fsobjp = fsobj.parent();

                          var fsobjp_ywidth = fsobjp.attr('ywidth');

                          var fcadd =  Math.ceil(Number(fsobjp_ywidth)/Number(tobj.attr('maxnum')));

                          var fsobjp_width = fsobjp.width();


                          if(type=='+'){

                            if(fsobjp_width-fcadd < 0){
                                var gwidth = 0;
                            }else{
                                var gwidth = fsobjp_width-fcadd;
                            }



                         }else if(type=='-'){

                            if(fsobjp_width+fcadd > fsobjp_ywidth){
                                var gwidth = fsobjp_ywidth;
                            }else{
                                var gwidth = fsobjp_width+fcadd;
                            }


                         }

                         fsobjp.css('background',objTF.shuliangtiaot).css('width',gwidth+'px');

                     }

                     var tnum = tobj.attr('num');

                     if(type=='+'){

                         tobj.attr('num',Number(tnum)-1).css('background','');

                         if(tobj.attr('num') == 0){
                            tobj.css('background',objTF.tcolor);
                         }

                     }else if(type=='-'){

                         tobj.attr('num',Number(tnum)+1).css('background','');

                         if(tobj.attr('num') != 0){
                            tobj.css('background','');
                         }

                     }

                     return true;

                }
           }



   }



/** 初始化
 *
 * 将注册表格添加索引和数据数量
 *
 *@param string ob 传入字符串判断给哪个表格添加索引
 *
 **/
 objTF.init = function(ob){
   if(ob=='t'){
      objTF.t.each(function(i){
        if(objTF.tnum.length > 1){
           var thisObj = $(this);

           thisObj.attr('index',i).attr('num',objTF.tnum[i]).attr('maxnum',objTF.tnum[i]);

           if(objTF.shuliangtiaot){
             var offset = thisObj.offset();

            thisObj.append($('<div>').attr('ywidth',thisObj.width()).css('background',objTF.shuliangtiaot).css('height','3px').append($('<div>').attr('id','t'+i).css('font-size','10px').css('text-align','center').css('width',thisObj.width()).css('position','absolute').css('margin','-5px 0 0 0').html(objTF.tnum[i])));
           }


           if(objTF.ttiji.length > 1){
              thisObj.attr('tiji',objTF.ttiji[i]);
           }else{
              thisObj.attr('tiji',objTF.ttiji[0]);
           }

        }else{
           var thisObj = $(this);

           thisObj.attr('index',i).attr('num',objTF.tnum[0]).attr('maxnum',objTF.tnum[0]);;

           if(objTF.tnum[0] == 999999999999) objTF.tnum[0] = 'oo';
           if(objTF.shuliangtiaot){
             var offset = thisObj.offset();

            thisObj.append($('<div>').attr('ywidth',thisObj.width()).css('background',objTF.shuliangtiaot).css('height','3px').append($('<div>').attr('id','t'+i).css('font-size','10px').css('text-align','center').css('width',thisObj.width()).css('position','absolute').css('margin','-5px 0 0 0').html(objTF.tnum[0])));
           }


           if(objTF.ttiji.length > 1){
               thisObj.attr('tiji',objTF.ttiji[i]);
           }else{
               thisObj.attr('tiji',objTF.ttiji[0]);
           }

        }
      });
   }else if(ob=='f'){
     objTF.f.each(function(i){
       if(objTF.fnum.length > 1){
            var thisObj = $(this);

           $(this).attr('index',i).attr('num',objTF.fnum[i]).attr('maxnum',objTF.fnum[i]).css('text-align','center');

           if(objTF.shuliangtiaof){
              var offset = thisObj.offset();
              var div1 = $('<div>').css('clear','both');
              var div2 = $('<div>').attr('ywidth',thisObj.width()).css('width','0px').css('height','3px').css('position','relative');
              var div3 = $('<div>').attr('id','d'+i).css('font-size','10px').css('text-align','center').css('width',thisObj.width()).css('position','absolute').css('margin','-5px 0 0 0').css('left','0').html(0+'/'+objTF.fnum[i]);

              var preg = /msie.*7|msie.*6/ig;
              if(preg.test(navigator.appVersion)){
                // div2.css('left','-50px');
              }

             thisObj.append(div1);
             thisObj.append(div2.append(div3));

           }

       }else{
             var thisObj = $(this);

           $(this).attr('index',i).attr('num',objTF.fnum[0]).attr('maxnum',objTF.fnum[0]).css('text-align','center');

           if(objTF.tnum[0] == 999999999999) objTF.tnum[0] = 'oo';
           if(objTF.shuliangtiaof){
              var offset = thisObj.offset();
              var div1 = $('<div>').css('clear','both');
              var div2 = $('<div>').attr('ywidth',thisObj.width()).css('width','0px').css('height','3px').css('position','relative');
              var div3 = $('<div>').attr('id','d'+i).css('font-size','10px').css('text-align','center').css('width',thisObj.width()).css('position','absolute').css('margin','-5px 0 0 0').html(0+'/'+objTF.fnum[0]);

              var preg = /msie.*7|msie.*6/ig;
              if(preg.test(navigator.appVersion)){
                // div2.css('left','-20px');
              }

            thisObj.append(div1);
            thisObj.append(div2.append(div3));

           }
       }
     });
   }

   $('body').append($('<div>').attr('id','objTnumshow').css('position','absolute').css('display','none'));
   $('body').append($('<div>').attr('id','objTeXiao').css('position','absolute').css('display','none'));

 }


/**  拖拽动画
 *
**/
 objTF.ST = function(){
      $(document).mousemove(function(event){

           var Event = event || window.event;
                   var left = Event.clientX+1;
                   var top = Event.clientY+1;
                   objTF.clone.css('left',left+'px').css('top',top+'px');
                   if(Event.button == 1){
                       //利用程序报错提前返回来启动放置表格的mouseup事件,并返回false关闭禁用拖动,针对ie(容易死机,不推荐使用)
                        //chucuole;
                       //返回false关闭禁用拖动,针对ie
                       return false;
                   }

      });

      $(document).mouseup(function(){

                $(document).unbind('mousemove');
                $('#huicang').remove();

      });
 }



/**  放置表格数量显示条控制器
 *
 *
 *@param string obj 在放置表格里的克隆对象
 *
**/
 objTF.FDataBH = function(obj){

      var thisObj  = obj;
      var thisObjp = thisObj.parent();

      //保留该克隆元素的原html
      var thisObj_html = thisObj.html();


      //用循环找出该克隆元素对应的仓库元素,替换掉该元素里多余的数量显示条信息
      var thisIndex =  thisObj.attr('index');
      for(var i=0; i<objTF.t.length; i++){

          var tobj = objTF.t.eq(i);
          var tobjIndex = tobj.attr('index');
          var tobjText =  tobj.html().replace(/<div.*\n*.*\/div>/ig,'');

          if(tobjIndex == thisIndex){

              thisObj.html(tobjText);

          }

      }


      //取得该物品的体积
      var ttiji = Number(thisObj.attr('tiji'));


      //判断数据处理类型
      if(objTF.type){

         thisObj.html(thisObj_html);
         var spannum = Number(thisObj.find('span[type=math]').html());

      }else{

         var spannum = 1;
      }


       //改变数量显示条的长度和数字
         if(objTF.shuliangtiaof){

                 $('body').append(thisObj);
                 var fsobj = $('#d'+thisObjp.attr('index'));

                 var repreg = /\/.*/ig;
                 var ptext = repreg.exec(fsobj.text());
                 var retext = fsobj.text().replace(repreg,'');

                 fsobj.html(Number(retext)-(spannum*ttiji)+ptext);
                 var fsobjp = fsobj.parent();

                 var fsobjp_ywidth = fsobjp.attr('ywidth');

                 var fcadd =  (Math.ceil(Number(fsobjp_ywidth)/Number(thisObjp.attr('maxnum'))))*spannum;

                 var fsobjp_width = fsobjp.width();

                 if(fsobjp_width-fcadd*ttiji < 0){
                     var gwidth = 0;
                 }else{
                     var gwidth = fsobjp_width-fcadd*ttiji;
                 }

                 fsobjp.css('background',objTF.shuliangtiaof).css('width',gwidth+'px');

           }

       //type为xin表示在放置表格外
       thisObj.attr('type','xin');

       //更新数量,并改变背景颜色
       var fnum = thisObjp.attr('num');

       thisObjp.attr('num',Number(fnum)+(spannum*ttiji)).css('background','');

 }



/**  在克隆对象上按下鼠标左键动作
 *
 *
**/
  objTF.CloneDown = function(event){

    var Event = event || window.event;
    if(Event.button == 0 || Event.button == 1){

      //使事件控制器true以激发放置表格鼠标弹起动作
      objTF.empty = true;

      var thisObj = $(this).css('position','absolute');

      //将该克隆元素赋值给objTF.data数组,使放置表格的鼠标弹起动作能获取到该数据
      objTF.index = thisObj.attr('index');
      objTF.data[objTF.index] = thisObj;

      objTF.clone = thisObj;

      if(objTF.clone.attr('type') == 'jiu'){
          objTF.clone.next('.jiantou').remove();
          $('body').append(objTF.clone);
          objTF.FDataBH(thisObj);


      }

       var offset = $(this).offset();
       var off_l = offset.left;
       var off_t = offset.top;


     objTF.client_X  = Event.clientX-off_l;
     objTF.client_Y  = Event.clientY-off_t;





      //执行拖拽动画
      objTF.ST();
      //返回false关闭禁用拖动,针对火狐
      return false;
     }

  }



/**  在克隆对象上按下鼠标右键动作
 *
 *@return boolen false 返回false屏蔽默认右键菜单
**/
  objTF.CloneDown2 = function(event){

    var Event = event || window.event;

    if(Event.button == 2 || Event.button == 0){

       var thisObj = $(this);
       objTF.clone = thisObj;

       var offset = thisObj.offset();

       //创建回仓div并绑定事件
       var huicang = $("<div id='huicang'>").css('position','absolute').css('left',offset.left+"px").css('top',offset.top+thisObj.height()+'px').css('cursor','default').html('退房').mouseover(function(){

          //鼠标划入改变背景色
         $(this).css('background','#a00');

       }).mouseout(function(){

          //鼠标离开改变背景色
         $(this).css('background','');

       }).mousedown(objTF.CloneDown2_Down);


       $('body').append(huicang);  //将配置好的回仓菜单插到body元素下

       //返回false屏蔽默认右键菜单
       return false;

    }

  }




/**  回仓动作
 *
 *
**/
  objTF.CloneDown2_Down = function(event){

       var Event = event || window.event;
       if(Event.button == 0 || Event.button == 1){

          //找到该克隆元素
          var cloneid =  objTF.clone.attr('id');
          var cloneObj = $('#'+cloneid);
          var cloneIndex = cloneObj.attr('index');

          //用循环找到该克隆元素对应的物品并控制数量显示条和剩余数量
          for(var i=0; i<objTF.t.length; i++){

               var tobj = objTF.t.eq(i);

               var tobjIndex = tobj.attr('index');

               if(tobjIndex == cloneIndex){

                   if(objTF.type){

                      var spannum = Number(objTF.clone.find('span[type=math]').html());

                      //如果为flash,则表示该克隆元素在body上,所以让spannum =1 进行库存的数据更新
                      if(!spannum){
                          spannum=1;
                      }

                   }else{

                       var spannum = 1;
                   }


                    if(objTF.shuliangtiaot){

                          var fsobj = $('#t'+tobj.attr('index'));

                          fsobj.html(Number(fsobj.text())+1*spannum);

                          var fsobjp = fsobj.parent();

                          var fsobjp_ywidth = fsobjp.attr('ywidth');

                          //计算显示条变动的宽度
                          var fcadd =  (Math.ceil(Number(fsobjp_ywidth)/Number(tobj.attr('maxnum'))))*spannum;

                          var fsobjp_width = fsobjp.width();


                          if(fsobjp_width+fcadd > fsobjp_ywidth){
                               var gwidth = fsobjp_ywidth;
                          }else{
                             var gwidth = fsobjp_width+fcadd;
                          }


                          fsobjp.css('background',objTF.shuliangtiaot).css('width',gwidth+'px');


                     }


                     var tnum = tobj.attr('num');

                     tobj.attr('num',Number(tnum)+1*spannum).css('background','');


                }
           }



          if(objTF.clone.attr('type') == 'jiu'){
                  objTF.FDataBH(objTF.clone);
           }

          cloneObj.next('.jiantou').remove();
          cloneObj.remove();   //删除该克隆元素

       }

   }



 return objTF;
}